/*
 * TelaResultado.java
 *
 * Created on 28 de Março de 2009, 17:30
 */

package iu;

import comp.racer.common.rn.Jogador;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import so.Cliente;

/**
 *
 * @author  Germano
 */
public class ClassificacaoTela extends JogadorTableHolder {

  
    /** Creates new form TelaResultado */
    public ClassificacaoTela(Map<Jogador, Integer> jogadorPosicaoRankingMap) {
        List<Jogador> classificacao = new Vector(jogadorPosicaoRankingMap.keySet());
        Collections.sort(classificacao);

        setClassificacao(classificacao);
        initComponents();
        updateComponents();
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        Integer posicaoRanking = jogadorPosicaoRankingMap.get( getCliente().getJogador() );
        if( !posicaoRanking.equals(-1)) {
            getLbAlertaRanking().setText("Parabéns! Voce entrou no ranking na posicao numero " + posicaoRanking + " !" );
        } else {
            getLbAlertaRanking().setText("");
        }

    }

  
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbTitulo = new javax.swing.JLabel();
        jspClassificacao = new javax.swing.JScrollPane();
        jtClassificacao = new javax.swing.JTable();
        okBt = new javax.swing.JButton();
        lbAlertaRanking = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("CompRacer - Classificação");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        lbTitulo.setText("Resultado");

        jtClassificacao.setModel(new javax.swing.table.DefaultTableModel(

        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtClassificacao.getTableHeader().setReorderingAllowed(false);
        jspClassificacao.setViewportView(jtClassificacao);

        okBt.setText("OK");
        okBt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okBtActionPerformed(evt);
            }
        });

        lbAlertaRanking.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbAlertaRanking.setText("Alerta de entrada no ranking");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lbAlertaRanking, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE)
                            .addComponent(jspClassificacao, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(178, 178, 178)
                        .addComponent(okBt))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(157, 157, 157)
                        .addComponent(lbTitulo)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbTitulo)
                .addGap(18, 18, 18)
                .addComponent(jspClassificacao, javax.swing.GroupLayout.PREFERRED_SIZE, 287, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(lbAlertaRanking, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(okBt)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void okBtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okBtActionPerformed
        fechaTela();
    }//GEN-LAST:event_okBtActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        // TODO add your handling code here:
        System.out.println("Tela Classificação fechada");
    }//GEN-LAST:event_formWindowClosed

    public void fechaTela(){
        getCliente().realizaDesconexao(0);

    }

    // getters e setters
    public JTable getJtClassificacao() {
        return jtClassificacao;
    }

    public void setJtClassificacao(JTable jtClassificacao) {
        this.jtClassificacao = jtClassificacao;
    }

    public JLabel getLbTitulo() {
        return lbTitulo;
    }

    public void setLbTitulo(JLabel lbTitulo) {
        this.lbTitulo = lbTitulo;
    }

    public JScrollPane getJspClassificacao() {
        return jspClassificacao;
    }

    public void setJspClassificacao(JScrollPane jspClassificacao) {
        this.jspClassificacao = jspClassificacao;
    }

    public JButton getOkBt() {
        return okBt;
    }

    public void setOkBt(JButton okBt) {
        this.okBt = okBt;
    }


    public JLabel getLbAlertaRanking() {
        return lbAlertaRanking;
    }

    public void setLbAlertaRanking(JLabel lbAlertaRanking) {
        this.lbAlertaRanking = lbAlertaRanking;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jspClassificacao;
    private javax.swing.JTable jtClassificacao;
    private javax.swing.JLabel lbAlertaRanking;
    private javax.swing.JLabel lbTitulo;
    private javax.swing.JButton okBt;
    // End of variables declaration//GEN-END:variables

}
